<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\TilModel;
use Illuminate\Http\Request;

class TilController extends Controller
{
    public function addtil()
    {
        return view("admin.tiladdpage");
    }


    public function inserttil(Request $request)
    {
        $data = $request->input();
        $id=$data['id'];
        unset($data['_token']);
        if($id==0) {
            $ok = TilModel::create($data);
            $result=["title"=>"数据添加成功","err"=>0];
            $result=json_encode($result);
            return $result;
        }else{
            $ok=TilModel::where("id",$id)->first();
            $ok->update($data);
            $result=["title"=>"数据编辑成功","err"=>0];
            $result=json_encode($result);
            return $result;
        }
    }


    public function tils(Request $request)
    {
        $data=TilModel::get();
        return view("admin.til",compact("data"));
    }


//    public function updatetil(Request $request)
//    {
//        $id=$request->input('id');
//        $ok=TilModel::where("id",$id)->first();
//        return view("admin.tiladdpage",compact("ok"));
//    }



    public function tildelete(Request $request)
    {
        $id=$request->input("id");
        $ok=TilModel::where("id",$id)->delete();
        $request=(["title"=>"删除成功","err"=>0]);
        $request=json_encode($request);
        return $request;
    }


    public function tilupdate(Request $request)
    {
        $id=$request->input("id");
        $ok=TilModel::where("id",$id)->first();
        return view("admin.tiladdpage",compact("ok"));
    }

    

}











